package com.ruoyi.tuanzhang.mapper.impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.tuanzhang.domain.DarenHomeVideoHistoryDo;
import com.ruoyi.tuanzhang.domain.excelDto.DarenHomeVideoHistoryExcelDto;
import com.ruoyi.tuanzhang.mapper.DarenBaseMapper;
import com.ruoyi.tuanzhang.mapper.DarenHomeVideoHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Component
public class DarenHomeVideoHistoryMapperImpl {
    @Autowired
    public static DarenBaseMapper darenBaseMapper;
    @Autowired
    private static DarenHomeVideoHistoryMapper darenHomeVideoHistoryMapper;
    private DarenHomeVideoHistoryMapperImpl (DarenBaseMapper baseMapper, DarenHomeVideoHistoryMapper videoHistoryMapper) {
        darenBaseMapper = baseMapper;
        darenHomeVideoHistoryMapper = videoHistoryMapper;
    }


    /**
     * 根据传进来的uid查找粉丝信息
     * @param uids 用户id
     * @param map  k:用户id  v:用户昵称
     * */
    public static List<DarenHomeVideoHistoryExcelDto> getSingleExcel(List<String> uids, Map<String, String> map) {
        if (Objects.isNull(uids) || uids.isEmpty()) {
            return new ArrayList<>();
        }
        QueryWrapper<DarenHomeVideoHistoryDo> wrapper = new QueryWrapper<>();
        wrapper.in("uid", uids);
        List<DarenHomeVideoHistoryDo> darenHomeVideoHistoryDos = darenHomeVideoHistoryMapper.selectList(wrapper);
        List<DarenHomeVideoHistoryExcelDto> list = JSONArray.parseArray(JSONArray.toJSONString(darenHomeVideoHistoryDos), DarenHomeVideoHistoryExcelDto.class);
        if (Objects.nonNull(list) && !list.isEmpty()) {
            for (DarenHomeVideoHistoryExcelDto excelDto : list) {
                excelDto.setNickname(map.get(excelDto.getUid()));
            }
        } else {
            return new ArrayList<>();
        }
        return list;
    }

}
